int pulseWidth=0; int rise=5; boolean forward=true; void setup() { // put your setup code here, to run once: pinMode (10, OUTPUT); pinMode (12, OUTPUT); pinMode (11, OUTPUT); digitalWrite (12, HIGH); digitalWrite (11, LOW); } void loop() { // put your main code here, to run repeatedly: pulseWidth = pulseWidth + rise; analogWrite (10, pulseWidth); //here's where we'll reverse the motor direction if the speed is at 0. if (pulseWidth <=0) { forward = !forward; rise = -rise; } if (forward == true){ digitalWrite (12, HIGH); digitalWrite (11, LOW); } else { digitalWrite (12, LOW); digitalWrite (11, HIGH); } if (pulseWidth >= 255){ rise = -rise; } delay (50); }